<%-- 
    Document   : addBookAction
    Created on : Feb 25, 2012, 2:30:50 AM
    Author     : Hiroroi
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@page import="java.sql.*, DBConnection.*, UserPackage.*" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
            String bookTitle, bookAuthor, synopsis, price;
            boolean result;
            int bookYear;
            
            bookTitle = request.getParameter("bookTitle");
            bookAuthor = request.getParameter("bookAuthor");
            bookYear = Integer.parseInt(request.getParameter("bookYear"));
            synopsis = request.getParameter("synopsis");
            price = request.getParameter("price");
            
           /* bookTitle = bookTitle.replaceAll("[^a-zA-Z0-9@._]", "");
            bookAuthor = bookAuthor.replaceAll("[^a-zA-Z0-9@._]", "");
            */
            inputChecker check = new inputChecker();
            if(check.stringCompare(bookTitle) && check.stringCompare(bookAuthor)){
            Product newBook = new Product();
            
            newBook.setBookTitle(bookTitle);
            newBook.setBookAuthor(bookAuthor);
            newBook.setBookYear(bookYear);
            newBook.setSynopsis(synopsis);
            newBook.setPrice(price);
            
            
            result = new ProductManager().addBook(newBook);
            if(result == true)
                response.sendRedirect("addBook.jsp");
            }
            else
                response.sendRedirect("prodMgrHomePage.jsp");
          %>
    </body>
</html>
